package common.model;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

import cn.hutool.core.collection.CollUtil;

@Data
public class MulitiDelayMessage<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    
    //消息体
    private T data;
    //记录延迟时间的集合
    private List<Long> delayTimes;

    // 无参构造函数，用于反序列化
    public MulitiDelayMessage() {
    }

    //获取消息和延迟时间的集合
    public MulitiDelayMessage(T data, List<Long> delayTimes) {
        this.data = data;
        this.delayTimes = delayTimes;
    }

    //创建一个新的MulitiDelayMessage对象
    public static <T> MulitiDelayMessage<T> of(T data, Long ... delayTimes) {
        return new MulitiDelayMessage<>(data, CollUtil.newArrayList(delayTimes));
    }

    //获取并移除延迟时间
    public Long removeDelayTime() {
        return delayTimes.remove(0);
    }

    //是否还有延迟时间
    public boolean hasDelayTime() {
        return !delayTimes.isEmpty();
    }
}
